package com.pp.controller;

import com.pp.model.Student;
import com.pp.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RequestMapping("/api")
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;
    @GetMapping("/students")
    @ResponseBody
    public List<Student>  findAll(){
        List<Student>  studentList=   studentService.findAll();
        return studentList;
    }
    @GetMapping("/students/{id}")
    @ResponseBody
    public Student  selectById(@PathVariable Integer id){
        Student student=   studentService.selectById(id);
        return student;
    }

    @GetMapping("/student/update")
    @ResponseBody
    public String  update(){
        Student student = new Student();
        student.setId(2);
        student.setAge(29);
        student.setName("ww");
        studentService.update(student);
        return "ok";
    }


    @GetMapping("/student/delete")
    @ResponseBody
    public String  delete(){
        Student student = new Student();
        student.setId(2);
        studentService.delete(student);
        return "ok";
    }

    @GetMapping("/student/insert")
    @ResponseBody
    public String  insert(){
        Student student = new Student();

        student.setAge(29);
        student.setName("er");
        studentService.insert(student);
        return "ok";
    }
}
